
#ifndef _WEBAPPLIB_HTTPCLIENT_H_
#define _WEBAPPLIB_HTTPCLIENT_H_ 

#include <string>
#include <vector>
#include <map>
#include <curl/curl.h>

using namespace std;

/// Web Application Library namaspace
namespace webapp {

class HttpClient {
	public:
		struct stRecvCtx
		{
			stRecvCtx()
			{
				m_sRecvBuffer = "";
			}
			string m_sRecvBuffer;
		};

		HttpClient( const string & url, const string & method="GET", bool isDebug = false );

		~HttpClient();
		
		void Reset();
		
		void SetUrl( const string & url );
		
		// ###### Set Post Data Method 1 ######################
		void FormAdd( const string & name, const string & content );

		void FormAddBinary( const string & name, const string & filepath, const string & filename );
		
		void SetFormAsPostData();

		// ###### Set Post Data Method 2 ######################
		// set normal form fiels, contenttype as application/x-www-form-urlencoded
		void SetFields( vector< pair<string,string> > & fieldsList );
		
		// ###### Set Post Data Method 3 ######################
		void SetRawPostData( const string & data, const string & contenttype = "" );
		
		int Execute();
	
		const string & GetContent();
	
		int Status();

	private:
		string m_sPostData;
		CURL * m_ptCurl;
		stRecvCtx m_tRecvCtx;
        struct curl_httppost* m_ptPost;
		struct curl_httppost* m_ptLast;
};

} // namespace

#endif //_WEBAPPLIB_HTTPCLIENT_H_ 

